<template>
  <div>
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>工作量审核
          </p>
        </div>
        <div class="topright" @click="$router.go(-1)">
          <el-button type="info">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe606;</span>返回
          </el-button>
        </div>
      </div>
    </div>

    <div class="main">
      <div style="width:1100px;margin:20px auto;">
        <button class="sumbitBtn" @click="handleSubInfo">提交审核</button>
      </div>
      <el-tabs v-model="activeName" type="border-card" @tab-click="handleClick" class="tabs-header">
        <el-tab-pane :label="'补盲扩'" name="first">
          <div class="expansion-amap">
            <!-- 地图展示 Start -->
            <expansion-amap
              style="margin-bottom:20px;"
              :readOnlyAmapData="readOnlyAmapData"
              v-loading="amapReadOnlyLoading"
              element-loading-text="地图加载中..."
              element-loading-spinner="el-icon-loading"
              v-if="!amapReadOnlyLoading"
            ></expansion-amap>
            <!-- 地图展示 End -->
          </div>
          <div class="gcl">
            <div class="title">
              补盲扩
              <span @click="checked = !checked">查看隐藏工程量</span>
            </div>
            <el-table :data="infodetail" tooltip-effect="dark" style border>
              <el-table-column label="序号" align="center" width="50" type="index"></el-table-column>
              <el-table-column label="线程/操作点" align="center" width="90" prop="point"></el-table-column>
              <el-table-column label="经纬度" align="center" width="95" prop="latAndlng"></el-table-column>
              <el-table-column label="工作项目名称" align="center" width="130" prop="optionName"></el-table-column>
              <el-table-column label="材料" align="center" width="100" prop="matName"></el-table-column>
              <el-table-column label="型号" align="center" width="100" prop="matModel"></el-table-column>
              <el-table-column label="单位" align="center" width="75" prop="unit"></el-table-column>
              <el-table-column label="预结算工作量" align="center" width="110" prop="budget"></el-table-column>
              <el-table-column label="修改工作量" align="center" width="100" prop="finalbudget"></el-table-column>
              <el-table-column label="备注" align="center" prop="correctCause"></el-table-column>
              <el-table-column label="操作" align="center" width="100" fixed="right">
                <template slot-scope="scope">
                  <a @click.prevent="edit(scope.row)">修改数量</a>
                </template>
              </el-table-column>
            </el-table>
          </div>

          <transition name="bounce">
            <div class="gcl"  v-if="checked">
              <div class="title">隐藏工作量</div>
              <el-table :data="infodetailSub" tooltip-effect="dark" style border>
                <el-table-column label="序号" align="center" width="50" type="index"></el-table-column>
                <el-table-column label="关联工作项目名称" align="center" width="300" prop="linkOptionName"></el-table-column>
                <el-table-column label="工作项目名称" align="center" prop="optionName"></el-table-column>
                <el-table-column label="单位" align="center" width="80" prop="testunit"></el-table-column>
                <el-table-column label="数量" align="center" width="100" prop="num"></el-table-column>
              </el-table>
            </div>
          </transition>
          <div class="gcl_footer">
            <div class="gcl_footer_top">
              <span>甲方结算合计：</span>
              <span>{{money.budget}} 元</span>
            </div>
            <div class="gcl_footer_bottom">
              <span>施工队费用合计：</span>
              <span>{{money.finalbudget}} 元</span>
            </div>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <!-- 修改数量 -->
    <div class="component-model">
      <el-dialog title="修改数量" :visible.sync="dialogVisible" width="600px">
        <el-form
          :model="ruleForm"
          ref="ruleForm"
          label-width="100px"
          class="demo-ruleForm"
          style="font-size: 12px"
        >
          <el-form-item label="施工内容：">
            <el-input v-model="ruleForm.optionName" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item label="单位：">
            <el-input v-model="ruleForm.unit" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item label="预结算数量：">
            <el-input v-model="ruleForm.budget" disabled="disabled"></el-input>
          </el-form-item>
          <div class="xiu">
            <span>修改数量：</span>
            <el-input-number
              v-model.number="ruleForm.finalbudget"
              controls-position="right"
              @change="handleChange"
              :min="0"
            ></el-input-number>
          </div>
          <el-form-item label="材料：">
            <el-input v-model="ruleForm.matName" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item label="备注：">
            <textarea
              v-model="ruleForm.correctCause"
              style="width:360px; margin-left:-98px;font-family: '微软雅黑';font-weight: 400;font-style: normal;font-size: 14px;color: #606266;text-align: left;box-sizing:border-box;resize: none;border-radius:3px;padding:9px 6px;border:1px solid #e4e4e4;outline:none;"
              placeholder="请输入内容..."
            ></textarea>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button @click="subChange">提交</el-button>
        </span>
      </el-dialog>
    </div>
  </div>
</template>
<script>
import expansionAmap from "./expansionAmap/expansionAmap";
export default {
  name: "teamWork",
  components: {
    expansionAmap
  },
  data() {
    return {
      // 选项卡name值
      activeName: "first",
      // 隐藏工作量表格的v-if bool值
      checked: false,
      //表格数据
      infodetail: [{}],
      // 弹窗bool值
      dialogVisible: false,
      // 修改数量的表单
      ruleForm: {
        optionName: "",
        finalbudget: "",
        budget: "",
        correctCause: "",
        matName:"",
        unit:""
      },
      ms_RoleName: localStorage.getItem("roleName"),
      // amap
      readOnlyAmapData: {}, // 施工队地图只读数据
      amapLoading: true, // 控制地图loading
      amapReadOnlyLoading: true,

      // 隐藏表格数据
      infodetailSub:[],
      // 费用
      money:{}
    };
  },
  created() {},
  mounted() {
    this.dataInit();
    this.getExpansionAmapData()
  },
  methods: {
    // 点击tab切换
    handleClick(tab, event) {
      //this.dataInit();
    },
    // 查询列表
    dataInit() {
      let tabs;
      switch (this.activeName) {
        case "first":
          tabs = "1";
          break;
      }
      let that = this,
        suCb = res => {
          console.log("查询结果", res);
          if(res.data.data.workLoads[0]!=null){
            that.infodetail = that.deepClone(res.data.data.workLoads);
            that.infodetailSub = that.deepClone(res.data.data.testWorkLoads)
            that.money = that.deepClone(res.data.data.settle)
          }
        },
        erCb = res => {},
        req = {
          url: "/api/web/proProject/queryBMKAuditWorkLoad",
          methods: "post",
          data: {
            proId:that.$route.params.proId
          },
          success: suCb,
          error: erCb
        };
      console.log("查询参数", req.data);
      that.$https(req);
    },
    // 修改数量
    edit(row) {
      this.dialogVisible = true;
      this.ruleForm.optionName = row.optionName;
      this.ruleForm.finalbudget = row.finalbudget;
      this.ruleForm.correctCause = row.correctCause;
      this.ruleForm.detailId = row.detailId;
      this.ruleForm.budget = row.budget;
      this.ruleForm.matName = row.matName;
      this.ruleForm.unit = row.unit;
      this.ruleForm.baseValue = row.baseValue;
      console.log(this.ruleForm);
    },
    // 修改数量提交
    subChange() {
      let that = this,
        suCb = res => {
          console.log("提交结果", res);
          if (res.data.flag == 1) {
            that.$message({
              message: "修改数量成功",
              type: "success"
            });
            that.dialogVisible = false;
            that.dataInit();
          }
        },
        erCb = res => {},
        req = {
          url: "/api/web/proMapWorkDetail/updateBMKWorkLoadDetail ",
          methods: "post",
          data: {
            detailId: that.ruleForm.detailId,
            correctWorkload: that.ruleForm.finalbudget + "",
            correctCause: that.ruleForm.correctCause,
            proId: that.$route.params.proId,
            unit:that.ruleForm.unit,
            submitWorkLoad: that.ruleForm.budget,
            baseValue:that.ruleForm.baseValue
          },
          success: suCb,
          error: erCb
        };
      console.log("提交参数", req.data);
      that.$https(req);
    },
    // 打印修改 数量的值
    handleChange(value) {
      console.log(value);
    },
    // 提交审核
    handleSubInfo() {
      let that = this,
        suCb = res => {
          console.log("提交结果结果", res.data.data);
          if (res.data.flag == 1) {
            that.$message({
              message: "提交成功",
              type: "success"
            });
            that.$router.go(-1);
          }
        },
        erCb = res => {
          console.log(res);
          that.dataInit();
        },
        req = {
          url: "/api/web/proProject/AuditBMKWorkLoadDetail",
          methods: "post",
          data:{
            proId: that.$route.params.proId,
            flowStep:''
          },
          success: suCb,
          error: erCb
        };
        req.data.flowStep = that.ms_RoleName == 'ProjectClerk'?'111':'101'
      console.log("提交参数", req.data);
      that.$https(req);
    },
     /**
     * 获取施工队上传数据后绘图的方法
     */
    getExpansionAmapData() {
      let succ = res => {
        res = res.data;
        if (res.flag == 1) {
          let data = res.data.MapPoints
          // 接口返回地图数据
          let pro_id = data.proId;
          let pro_lnglat = [data.lng, data.lat];
          let points = data.mapPointList;

          this.readOnlyAmapData.pro_id = pro_id;
          this.readOnlyAmapData.pro_lnglat = pro_lnglat;
          this.readOnlyAmapData.points = points;
          this.amapReadOnlyLoading = false;
        }
      };
      let err = res => {
        that.$erMsg('网络错误')
      };
      let params = {
        proId: this.$route.params.proId
      };
      // let params = {
      //   proId: "testdetail"
      // }
      let data = {
        url: "/api/web/proProject/queryBMKWorkLoad",
        methods: "post",
        data: params,
        success: succ,
        error: err
      };
      // console.log("TCL: getExpansionAmapData -> this.$route.params.info", this.$route.params.proId)
      if (params.proId) {
        this.$https(data);
      }

      // mock的模拟数据
      // this.$axios.get("/mock/queryFinalWorkLoad.json").then(res => {
      //   // console.log(res,"axios.get")
      //   succ(res);
      // });
    }
  }
};
</script>
<style scoped>
.bounce-enter {
  margin-top: -100px;
}
.bounce-enter-active {
  transition: all 1s ease;
}

.bounce-enter-to {
  margin-top: 0px;
}

.bounce-leave-active {
  transition: all 0.3s ease;
}

.main {
  width: 1100px;
  margin: 20px auto;
  text-align: left;
}
.gcl {
  margin-bottom: 20px;
}
.gcl .title {
  background: #f8f8f8;
  height: 35px;
  line-height: 35px;
  color: #666;
  padding: 0 20px;
  font-size: 14px;
  border: 1px solid #e4e4e4;
  border-bottom: none;
  text-align: left;
}
a {
  color: #1abc9c;
  cursor: pointer;
  text-decoration: none;
}
.xiu {
  text-align: left;
  margin-bottom: 20px;
}
.xiu span {
  display: inline-block;
  text-align: right;
  width: 85px;
  margin-right: 15px;
}

.gcl span {
  float: right;
  font-size: 12px;
  border: 1px solid rgba(204, 204, 204, 1);
  margin-top: 4px;
  width: 120px;

  line-height: 26px;
  text-align: center;
}
.gcl span:hover {
  cursor: pointer;
  opacity: 0.7;
}

/* 工程量管理 底部 价格显示 */
.gcl_footer {
  text-align: right;
}

.gcl_footer .gcl_footer_top {
  margin-bottom: 10px;
  font-size: 18px;
}

.gcl_footer .gcl_footer_top span:nth-child(2n),
.gcl_footer .gcl_footer_bottom span:nth-child(2n) {
  color: #1abc9c;
}

.gcl_footer .gcl_footer_bottom {
  margin-bottom: 10px;
  font-size: 19px;
}

.sumbitBtn {
  width: 120px;
  height: 35px;
  line-height: 35px;
  color: #1abc9c;
  background-color: #fff;
  border: 1px solid #1abc9c;
  border-radius: 5px;
}

.sumbitBtn:hover {
  color: #fff;
  background-color: #1abc9c;
}

/* expansion-amap Start*/
.expansion-amap {
  widows: 100%;
}
/* expansion-amap End and 地图容器 Start */
.amap {
  width: 100%;
  height: 500px;
  position: relative;
}
#container {
  position: absolute;
  width: 100%;
  height: 100%;
}
</style>


<!-- 在全局中修改地图的css -->
<style>
.expansion-amap .marker-container {
  position: relative;
}
.expansion-amap .marker-container img {
  position: absolute;
}
.expansion-amap .marker-container div:nth-child(2) {
  color: red;
  position: absolute;
  top: -20px;
  left: 0;
}
.expansion-amap .marker-container div:nth-child(3) {
  height: 20px;
  line-height: 20px;
  padding: 3px 6px;
  background: #fff;
  border: 1px solid red;
  position: absolute;
  left: 6px;
  top: 6px;
}
</style>
